# Maintainer: Wolfgang Walther <opensource@technowledgy.de>
pkgname=nss_wrapper
pkgver=1.1.12
pkgrel=1
pkgdesc="A wrapper for the user, group and hosts NSS API"
url="https://cwrap.org/nss_wrapper.html"
arch="all !ppc64le" # test case segfaults in ppc64le
license="BSD-3-Clause"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="cmake musl-nscd-dev samurai"
checkdepends="cmocka-dev"
subpackages="$pkgname-dev $pkgname-doc"
source="https://ftp.samba.org/pub/cwrap/nss_wrapper-$pkgver.tar.gz
	tests.patch
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DUNIT_TESTING="$(want_check && echo ON || echo OFF)" \
		$CMAKE_CROSSOPTS .
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

dev() {
	default_dev
	mv "$subpkgdir"/usr/lib/libnss_wrapper.so "$pkgdir"/usr/lib
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	# To avoid adding perl as a dependency, the nss_wrapper.pl script is removed.
	# It's not even mentioned in the manpage, either.
	rm "$pkgdir"/usr/bin/nss_wrapper.pl
}

sha512sums="
ff2efc70b29b30a2761952637c3794e73da2c8ae9273222b146e62312acd2b3bdecfca54722ca86c9a2fd700162717782b2b8f8072e76c17657e44c602911a2b  nss_wrapper-1.1.12.tar.gz
0291b7d8c7c83f3b933dfd3cc63f571dedb5db0dd209eef412e4531f822bab5bdbe40cd3f979707187e5aac3065c95e65932660862a56f37168950ad034a34ce  tests.patch
"
